

export async function sendMessage (msg:Record<string, any>) {
  const tabs = await chrome.tabs.query({ active: true })
  if (!tabs[0].id) {return}
  chrome.tabs.sendMessage(tabs[0].id, msg, (res) => {
    console.log(res)
  })
}


// 监听来自content-script的消息
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
  console.log('收到来自Popup的消息：')
  console.log(request, sender, sendResponse)
  sendResponse('我是后台，我已收到你的消息：' + JSON.stringify(request))
})
